Skip to content

Conversation

@philprime
Copy link
Member

@philprime philprime commented Jan 12, 2026

📜 Description

This PR converts the auto breadcrumb tracking integration and related types from Objective-C to Swift. The main conversion includes:

  • SentryAutoBreadcrumbTrackingIntegration - Main integration class
  • SentrySystemEventBreadcrumbs - System event breadcrumb tracking

Additionally, SentryBreadcrumbDelegate and SentryBreadcrumbTracker were also converted to Swift due to Swift-Objective-C interoperability compilation issues encountered during the migration. Converting these types to Swift was more reasonable than attempting to fix the complex interop issues, especially given the project's direction toward Swift.

The conversion also includes:

  • Refactored UICurrentDeviceProvider to use uiDeviceWrapper from SentryDependencyContainer via a new SentryUIDeviceWrapperProvider protocol
  • Added swizzleViewDidAppear helper method to SentrySwizzleWrapperHelper to support Swift-based swizzling
  • Fixed pre-existing header path issue for SentryAsyncSafeLog.h that was exposed by stricter SPM build requirements

💡 Motivation and Context

This change is part of the ongoing migration from Objective-C to Swift in the Sentry Cocoa SDK. Converting the breadcrumb tracking integration to Swift improves code maintainability, type safety, and consistency with the rest of the Swift codebase.

The additional conversion of SentryBreadcrumbDelegate and SentryBreadcrumbTracker was necessary due to Swift-Objective-C interoperability compilation issues. Rather than attempting to resolve complex interop problems, converting these types to Swift was the more pragmatic approach and aligns with the project's Swift migration goals.

💚 How did you test it?

  • Verified SDK builds successfully for iOS, macOS, tvOS, watchOS, and visionOS
  • Ran unit tests: make test-ios
  • Verified breadcrumb tracking functionality works correctly
  • Confirmed no linter errors
  • Fixed pre-existing SentryAsyncSafeLog.h header path issue for SPM builds

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

Closes #6860
Closes #7258

Convert SentryAutoBreadcrumbTrackingIntegration from Objective-C to
Swift following the SwiftIntegration protocol pattern. Updated the
conversion guide with learnings including:

- Exposing Objective-C headers via SentryPrivate.h
- Runtime initialization pattern for conditionally compiled classes
- Typealias dependency injection pattern
- Test fixture setup with dependency injection
@philprime philprime self-assigned this Jan 12, 2026
@philprime philprime added the ready-to-merge Use this label to trigger all PR workflows label Jan 12, 2026
@philprime
Copy link
Member Author

@sentry review

@github-actions
Copy link
Contributor

github-actions bot commented Jan 12, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Add install_groups support by noahsmartin in #7278

Bug Fixes 🐛

  • Prevent deadlock in SentryReachability by notifying observers outside the lock by itaybre in #7246

Internal Changes 🔧

  • (release) Fix changelog-preview permissions by BYK in #7262
  • Convert AutoBreadcrumbTrackingIntegration to Swift by philprime in #7158
  • Fix SwiftLint script warning by itaybre in #7267
  • Convert SentryNSDataSwizzling and SentryNSFileManagerSwizzling to Swift by itaybre in #7209
  • Convert SentrySessionReplayIntegration to Swift by itaybre in #7102
  • Fix incomplete comment by itaybre in #7239

Other

  • test: Fix SentryDestinationTests to handle array type for tags by itaybre in #7240

🤖 This preview updates automatically when you update the PR.

@codecov
Copy link

codecov bot commented Jan 12, 2026

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
4441 5 4436 51
View the top 3 failed test(s) by shortest run time
SentryCrashReportStore_Tests::testPruneReports
Stack Traces | 0s run time
.../SentryTests/SentryCrash/SentryCrashReportStore_Tests.m:126 - ((sentrycrashcrs_getReportCount()) equal to (reportCount)) failed: ("7") is not equal to ("8")
SentryTests.PrivateSentrySDKOnlyTests::testProfilingStartAndCollect
Stack Traces | 0s run time
.../Tests/SentryTests/PrivateSentrySDKOnlyTests.swift:271 - XCTAssertGreaterThan failed: ("0") is not greater than ("0")
SentryTests.SentryFileManagerTests::testCreateDirectoryIfNotExists_successful_shouldNotLogError
Stack Traces | 0s run time
.../SentryTests/Helper/SentryFileManagerTests.swift:1056 - XCTAssertEqual failed: ("2") is not equal to ("0")
View the full list of 2 ❄️ flaky test(s)
SentryCrashReportStore_Tests::testCrashReportCount1

Flake rate in main: 99.12% (Passed 1 times, Failed 112 times)

Stack Traces | 0s run time
.../SentryTests/SentryCrash/SentryCrashReportStore_Tests.m:126 - ((sentrycrashcrs_getReportCount()) equal to (reportCount)) failed: ("0") is not equal to ("1")
SentryCrashReportStore_Tests::testDeleteAllReports

Flake rate in main: 99.12% (Passed 1 times, Failed 112 times)

Stack Traces | 0s run time
.../SentryTests/SentryCrash/SentryCrashReportStore_Tests.m:126 - ((sentrycrashcrs_getReportCount()) equal to (reportCount)) failed: ("3") is not equal to ("4")

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

…yAutoBreadcrumbTrackingIntegration

This update adds the @objc annotation to the addBreadcrumb method, allowing it to be accessible from Objective-C code. Additionally, the import statement in the test file has been adjusted for consistency with Swift's SPI usage.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1221.40 ms 1258.48 ms 37.08 ms
Size 24.14 KiB 1.08 MiB 1.06 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
edcda5a 1217.52 ms 1248.72 ms 31.20 ms
2e5230b 1207.41 ms 1240.41 ms 33.00 ms
3b01aaf 1194.98 ms 1210.36 ms 15.38 ms
387fbe4 1226.19 ms 1251.98 ms 25.79 ms
7e93d85 1205.28 ms 1243.71 ms 38.44 ms
5d67f5d 1225.33 ms 1262.76 ms 37.43 ms
45eb835 1210.40 ms 1233.39 ms 22.99 ms
37bc095 1210.00 ms 1242.69 ms 32.69 ms
ffe0649 1213.35 ms 1248.64 ms 35.29 ms
c424b6a 1220.38 ms 1248.18 ms 27.80 ms

App size

Revision Plain With Sentry Diff
edcda5a 24.14 KiB 1.08 MiB 1.06 MiB
2e5230b 24.14 KiB 1.04 MiB 1.02 MiB
3b01aaf 24.14 KiB 1.06 MiB 1.04 MiB
387fbe4 24.14 KiB 1.07 MiB 1.04 MiB
7e93d85 24.14 KiB 1.06 MiB 1.04 MiB
5d67f5d 24.14 KiB 1.06 MiB 1.04 MiB
45eb835 24.14 KiB 1.07 MiB 1.04 MiB
37bc095 24.14 KiB 1.06 MiB 1.04 MiB
ffe0649 24.14 KiB 1.06 MiB 1.04 MiB
c424b6a 24.14 KiB 1.06 MiB 1.04 MiB

Previous results on branch: philprime/convert-auto-breadcrumb-tracking-integration

Startup times

Revision Plain With Sentry Diff
02928a5 1217.57 ms 1243.44 ms 25.86 ms
a17d780 1210.94 ms 1251.53 ms 40.59 ms
d98c918 1224.55 ms 1259.49 ms 34.94 ms
d32640b 1214.98 ms 1242.67 ms 27.69 ms
bd74c60 1216.17 ms 1249.17 ms 33.00 ms
424ea88 1224.00 ms 1260.90 ms 36.90 ms

App size

Revision Plain With Sentry Diff
02928a5 24.14 KiB 1.08 MiB 1.05 MiB
a17d780 24.14 KiB 1.09 MiB 1.06 MiB
d98c918 24.14 KiB 1.07 MiB 1.05 MiB
d32640b 24.14 KiB 1.07 MiB 1.05 MiB
bd74c60 24.14 KiB 1.07 MiB 1.04 MiB
424ea88 24.14 KiB 1.07 MiB 1.05 MiB

@philprime
Copy link
Member Author

@sentry review

…ting functionality to Swift with updated conditional imports for platform compatibility.
…header file. Adjust usage in InfoForBreadcrumbController to align with new method definition.
@philprime philprime marked this pull request as ready for review January 23, 2026 08:27
Copy link
Contributor

@itaybre itaybre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some small comments

- Store notification observers and remove them in stop() to prevent
  resource leaks in SentryBreadcrumbTracker
- Track and disable battery monitoring and orientation notifications
  in stop() to prevent resource leaks in SentrySystemEventBreadcrumbs
- Inject dateProvider via initializer instead of using singleton
…o-breadcrumb-tracking-integration

# Conflicts:
#	Sources/Sentry/SentrySDKInternal.m
#	Sources/Sentry/SentrySwizzleWrapperHelper.m
#	Sources/Sentry/include/SentrySwizzleWrapperHelper.h
#	Sources/Swift/Core/Integrations/Integrations.swift
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

- Added a new swizzle method for tracking UIViewController lifecycle events.
- Updated conditional UIKit imports to support tvOS and visionOS.
- Adjusted test to reflect changes in notification observer count.
@philprime philprime enabled auto-merge (squash) January 26, 2026 16:25
… multi-platform support

- Modified conditional compilation to include tvOS and visionOS in SentryDependencyContainer.
- Added platform checks for battery and orientation notifications in SentrySystemEventBreadcrumbs to ensure proper functionality across iOS, tvOS, and visionOS.
- Cleaned up observer removal logic to prevent resource leaks.
@philprime philprime merged commit 2d59844 into main Jan 27, 2026
264 of 271 checks passed
@philprime philprime deleted the philprime/convert-auto-breadcrumb-tracking-integration branch January 27, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ref: convert AutoBreadcrumbTrackingIntegration to Swift Refactor SentryAutoBreadcrumbTrackingIntegration.m in Swift

4 participants